<?php
	
	// Session
	session_start();
	

	// Nese leximi i faqes behet nga ndonje burim ekstern duke mos e definuar identifikatorin e librit
	if (!isset($_GET['id'])) {
		header("Location: ../comunity/index.php?spalsh=wrong");
		exit;
	}
	
	
	// Integrimi i skedave sistemore
    include('../include/functions.inc.php');
	
	
	// Ndyshoret primare
	define('UID',$_SESSION['user_id']);
	define('ID',$_GET['id']);
	
	
	// DB CONNECT
	dbOpen("comunity");
	

	// ACTIONS
	if (isset($_GET['action']) && isset($_SESSION['user_id'])) {
	
		// Get dhe Vars from db
		$query = mysql_query("SELECT bookmark,completed FROM bookmarks WHERE book_id = '".ID."' AND user_id = '".UID."' ");
		$ROW = mysql_fetch_assoc($query);
	
		
		// Nese ekziston nje resht ne arkive, ben UPDATE
		if (mysql_num_rows($query) > 0) {
					
			// Nese libri akoma nuk eshte i registruar si i perfunduar
			if ($ROW[$_GET['action']] != 1) 
				mysql_query("UPDATE bookmarks SET ".$_GET['action']." = '1' WHERE book_id = '".ID."' ");
		}
		// Perndyshe ben INSERT		
		else 
			mysql_query("INSERT INTO bookmarks SET book_id = '".ID."', user_id = '".UID."', ".$_GET['action']." = '1' ");
				
			
		// Redirect
		$sid = implode(mysql_fetch_assoc(mysql_query("SELECT sid FROM library WHERE id = '".ID."'")));
		header("Location: index.php?id=".$sid."&splash=".$_GET['action']."");
		exit;
	}
	else {
	
		// Redirect to login page
		header("Location: ../members/login.php?splash=".$_GET['action']."");
		exit;
	}

?> 